<template>
  <div class="opinionpage">
    <el-form :model="form" :rules="rules" ref="form" label-width="100px" >
        <el-form-item label="手机号" prop="phone">
            <el-input v-model="form.phone" ></el-input>
        </el-form-item>
        <el-form-item label="反馈意见" prop="description">
            <el-input type="textarea" v-model="form.description"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submitForm('form')">提交</el-button>
        </el-form-item>
    </el-form>
  </div>
</template>

<script>
import Api from '@/api'
export default {
    data() {
        return {
            form: {},
            rules: {
                phone: [
                    { required: true, message: '请输入手机号', trigger: 'blur' }
                ],
                description: [
                { required: true, message: '请输入意见内容', trigger: 'blur' }
                ]
            }
        }
    },
    methods: {
        submitForm(form) {
            this.$refs[form].validate( async (valid) => {
            if (valid) {
                const res = await Api.feedback(this.form)
                console.log(res)
                if (res.success) {
                    this.$message.success('提交成功')
                    this.$refs[form].resetFields();
                } else {
                    this.$message.error(res.msg)
                }
            } else {
                console.log('error submit!!');
                return false;
            }
            });
        }
    }
}
</script>

<style lang="scss" scoped>
.opinionpage {
    margin-top: 20px;
}
.el-form {
    width: 50%;
    min-width: 500px;
}
</style>